package ar.edu.utn.frba.dds.tp.transformers;

import org.joda.time.LocalDate;
import org.uqbar.arena.bindings.Transformer;

import ar.edu.utn.frba.dds.tp.code.dateParser.FormatoSimple;

public class StringToFechaTransformer implements Transformer<LocalDate, String> {

	@Override
	public Class<LocalDate> getModelType() {
		return LocalDate.class;
	}

	@Override
	public Class<String> getViewType() {
		return String.class;
	}

	@Override
	public String modelToView(LocalDate date) {
		if (date==null)
			return "";
		return date.toString();
	}

	@Override
	public LocalDate viewToModel(String s) {
		
		if(s.length() == 0)
			return null;
		
		return new FormatoSimple("dd/MM/yyyy").parse(s);
	}
	
}
